#include <REGX52.H>
#define uchar unsigned char
#define uint unsigned int
void delay(uint t){
	while(t--);
}
sbit row0=P3^0;sbit row1=P3^1;sbit row2=P3^2;sbit row3=P3^3;
sbit col0=P3^4;sbit col1=P3^5;sbit col2=P3^6;sbit col3=P3^7;
uchar dw,gw;

uchar keycode(){
	uchar k=' ';
	row0=row1=row2=row3=1;
	row0=0;k=col0==0?0:col1==0?1:col2==0?2:col3==0?3:k;row0=1;
	row1=0;k=col0==0?4:col1==0?5:col2==0?6:col3==0?7:k;row1=1;
	row2=0;k=col0==0?8:col1==0?9:col2==0?10:col3==0?11:k;row2=1;
	row3=0;k=col0==0?12:col1==0?13:col2==0?14:col3==0?15:k;row3=1;
	return k;
}
 void InitT0(){
 	TMOD=0x01;
	TH0=gw;
	TL0=dw;
	EA=1;
	ET0=1;
 }
 uint code music[]={
 0xF91F,0xF9DF,0xFA8A,0xFAD9,0xFB68,0xFBE9,0xFC5B,0xff,
 0xFC9E,0xFCEF,0xFD45,0xFD6C,0xFDB4, 0xFDF4,0xFE2D ,0xff,
 };
void main(){
	uchar key;
	InitT0();
	while(1){
		key=keycode();
		if(key!=' '){
			gw=music[key]/256;
			dw=music[key]%256;
			TR0=1;
		}
		else TR0=0,P2_3=1;
	}
}		
void T0_timer() interrupt 1
{
	P2_3=!P2_3;
	TH0=gw;
	TL0=dw;		
}			  